package com.example.shipload_e.util;

import android.annotation.SuppressLint;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@SuppressLint("SimpleDateFormat")
public class SystemDateTools {
	public static final String	DEFAULT_FORMAT_TYPE	= "yyyy-MM-dd";

	/**
	 * 获取系统时间
	 * @return
	 */
	public static String getDate() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss ");
		Date dateInfo = new Date();
		return sdf.format(dateInfo);
	}

	/**
	 * 获取系统日期
	 * @return
	 */
	public static String getDateByNow() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date dateInfo = new Date();
		return sdf.format(dateInfo);
	}

	/**
	 * 获取系统时间
	 * @return
	 */
	public static String getTimeByNow() {
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
		Date dateInfo = new Date();
		return sdf.format(dateInfo);
	}

	public static String getDateByNowByType(String infoType) {
		SimpleDateFormat sdf = new SimpleDateFormat(infoType);
		Date dateInfo = new Date();
		return sdf.format(dateInfo);
	}

	/**
	 * 获取年份
	 * @return
	 */
	public static String getYearFromDate() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
		Date dateInfo = new Date();
		return sdf.format(dateInfo);

	}

	/**
	 * 获取月份
	 * @return
	 */
	public static String getMonthFromDate() {
		SimpleDateFormat sdf = new SimpleDateFormat("MM");
		Date dateInfo = new Date();
		return sdf.format(dateInfo);

	}

	/**
	 * 获取日
	 * @return
	 */
	public static String getDayFromDate() {
		SimpleDateFormat sdf = new SimpleDateFormat("dd");
		Date dateInfo = new Date();
		return sdf.format(dateInfo);

	}

	/**
	 * 获取时间
	 * @return
	 */
	public static String getSystemTime() {
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
		Date dateInfo = new Date();
		return sdf.format(dateInfo);

	}

	/**
	 * 获取时
	 * @return
	 */
	public static String getSystemHourOfTime() {
		SimpleDateFormat sdf = new SimpleDateFormat("HH");
		Date dateInfo = new Date();
		return sdf.format(dateInfo);

	}

	/**
	 * 获取分
	 * @return
	 */
	public static String getSystemMinuteOfTime() {
		SimpleDateFormat sdf = new SimpleDateFormat("mm");
		Date dateInfo = new Date();
		return sdf.format(dateInfo);

	}

	/**
	 * 获取秒
	 * @return
	 */
	public static String getSystemSecondsOfTime() {
		SimpleDateFormat sdf = new SimpleDateFormat("ss");
		Date dateInfo = new Date();
		return sdf.format(dateInfo);

	}

	/**
	 * 以指定格式格式化时间
	 * @param dateStr
	 *            需要格式化的时间
	 * @param formatType
	 *            格式
	 * @return 格式化后的值
	 * @throws ParseException
	 */
	@SuppressLint("SimpleDateFormat")
	public static Date parseString(String dateStr,String formatType) throws ParseException {
		if(formatType == null || "".equals(formatType)) {
			formatType = DEFAULT_FORMAT_TYPE;
		}
		SimpleDateFormat sdf = new SimpleDateFormat(formatType);
		return sdf.parse(dateStr);
	}
}
